import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

import 'index.dart';

/// slider indicator 指示器
class SliderIndicatorWidget extends StatelessWidget {
  /// 个数
  final int length;

  /// 当前位置
  final int currentIndex;

  /// 颜色
  final Color color;

  /// 是否圆形
  final bool isCircle;

  /// 对齐方式
  final MainAxisAlignment alignment;

  const SliderIndicatorWidget({
    Key? key,
    required this.length,
    required this.currentIndex,
    Color? color,
    this.isCircle = false,
    this.alignment = MainAxisAlignment.center,
  })  : color = color ?? Colors.red,
        super(key: key);

  @override
  Widget build(BuildContext context) {
    return Row(
      mainAxisAlignment: alignment,
      children: List.generate(
        length,
        (index) {
          return Container(
            margin: EdgeInsets.symmetric(horizontal: 3.w),
            width: !isCircle ? 30.w : 6.w,
            height: !isCircle ? 3.w : 6.w,
            decoration: CommonDecoration.getShapeDecoration(
              bg: currentIndex == index ? color : Colors.white,
              radius: isCircle ? 6.w : 3.w,
            ),
          );
        },
      ),
    );
  }
}
